import NonFungibleToken from "../contracts/NonFungibleToken.cdc"
import NftEggsNFT from "../contracts/NftEggsNFT.cdc"

//此脚本使用NFTMinter资源创建新的NFT
//它必须使用具有minter资源的帐户运行
//存储在/storage/NFTMinter中

transaction(recipient: Address, setId: String, itemId: String, creator: String, title: String, asset: String, serial: String) {

    // 用于存储minter引用的局部变量
    let minter: &NftEggsNFT.NFTMinter

    prepare(signer: AuthAccount) {

        // 对存储器中NFTMinter资源的引用
        self.minter = signer.borrow<&NftEggsNFT.NFTMinter>(from: /storage/NFTMinter)
            ?? panic("Could not borrow a reference to the NFT minter")
    }

    execute {
        // 收件人的公共NFT集合
        let receiver = getAccount(recipient)
            .getCapability(/public/NFTCollection)
            .borrow<&{NftEggsNFT.NftEggsNFTCollectionPublic}>()
            ?? panic("Could not get receiver reference to the NFT Collection")

        // 铸造NFT并将其存入收件人的收藏
        self.minter.mintNFT(recipient: receiver, metadata: {"setId": setId, "itemId": itemId, "creator": creator, "title": title, "asset": asset, "serial": serial})
    }
}
